﻿409.最长回文串
int longestPalindrome(char* s) {
    int arr[26] = { 0 };
    int Arr[26] = { 0 };
    for (int i = 0; i < strlen(s); i++)
    {
        if (s[i] >= 'a' && s[i] <= 'z')
        {
            arr[s[i] - 'a']++;
        }
        else
        {
            Arr[s[i] - 'A']++;
        }
    }

    int ans = 0, count = 0;
    for (int i = 0; i < 26; i++)
    {
        if (arr[i] % 2 == 0)
        {
            ans += arr[i];
        }
        else if (arr[i] == 1)
        {
            count++;
        }
        else
        {
            ans += arr[i] - 1;
            count++;
        }

        if (Arr[i] % 2 == 0)
        {
            ans += Arr[i];
        }
        else if (Arr[i] == 1)
        {
            count++;
        }
        else
        {
            ans += Arr[i] - 1;
            count++;
        }
    }

    if (count >= 1)
    {
        ans++;
    }

    return ans;
}

412.Fizz Buzz
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
char** fizzBuzz(int n, int* returnSize) {
    char** ans = (char**)malloc(sizeof(char*) * n);
    *returnSize = 0;

    for (int i = 1; i <= n; i++)
    {
        char* temp = (char*)malloc(sizeof(char) * 9);
        if (i % 3 == 0 && i % 5 == 0)
        {
            sprintf(temp, "FizzBuzz");
        }
        else if (i % 3 == 0)
        {
            sprintf(temp, "Fizz");
        }
        else if (i % 5 == 0)
        {
            sprintf(temp, "Buzz");
        }
        else
        {
            sprintf(temp, "%d", i);
        }

        ans[(*returnSize)++] = temp;
    }
    return ans;
}

415.字符串相加
char* addStrings(char* num1, char* num2) {
    int n = strlen(num1) - 1, m = strlen(num2) - 1, count = 0, size = 0;
    char* ans = (char*)malloc(sizeof(char) * (fmax(n, m) + 3));

    while (n >= 0 || m >= 0)
    {
        int x = n < 0 ? 0 : num1[n] - '0';
        int y = m < 0 ? 0 : num2[m] - '0';
        int temp = (x + y + count) % 10;
        count = (x + y + count) / 10;
        ans[size++] = temp + '0';
        n--;
        m--;
    }

    if (count != 0)
    {
        ans[size++] = count + '0';
    }
    ans[size] = '\0';

    int l = 0, r = size - 1;
    while (l < r)
    {
        char temp = ans[l];
        ans[l] = ans[r];
        ans[r] = temp;
        l++;
        r--;
    }
    return ans;
}

434.字符串中的单词数
int countSegments(char* s) {
    int ans = 0, flag = 0;
    for (int i = 0; i < strlen(s); i++)
    {
        if (s[i] == ' ')
        {
            if (flag == 1)
            {
                ans++;
            }
            flag = 0;
        }
        else
        {
            flag = 1;
        }
    }
    if (flag == 1)
    {
        ans++;
    }
    return ans;
}

441.排列硬币
int arrangeCoins(int n) {
    long sum = 0, ans = 0;
    for (int i = 1; i <= n; i++)
    {
        sum += i;
        if (sum == n)
        {
            ans = i;
            break;
        }
        if (sum > n)
        {
            ans = i - 1;
            break;
        }
    }
    return ans;
}